Skip to content

Conversation

@clementval
Copy link
Contributor

Array with CONSTANT attribute declared in module spec part are device arrays and should not trigger the host array check.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Dec 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Array with CONSTANT attribute declared in module spec part are device arrays and should not trigger the host array check.


Full diff: https://github.com/llvm/llvm-project/pull/120333.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+1)
  • (modified) flang/test/Semantics/cuf09.cuf (+7)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 15ee5f32f69b19..bec3969c7a26b7 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -114,6 +114,7 @@ struct FindHostArray
           (!details->cudaDataAttr() ||
               (details->cudaDataAttr() &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Device &&
+                  *details->cudaDataAttr() != common::CUDADataAttr::Constant &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Managed &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Shared &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Unified))) {
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index 7452ee7cd7dc6a..b45ca6d7d1a9d7 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -1,6 +1,7 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
 module m
  integer :: m(100)
+ integer, constant :: c(10)
  integer, parameter :: p(5) = [1,2,3,4,5]
  contains
   attributes(device) subroutine devsub
@@ -42,6 +43,12 @@ module m
     i = threadIdx%x
     a(i) = s(10) ! ok, a is device and s is shared
   end subroutine
+
+  attributes(global) subroutine cstarray(a)
+    integer, device :: a(10)
+    i = threadIdx%x
+    a(i) = c(10) ! ok, a is device and c is constant
+  end subroutine
 end
 
 program main

@clementval clementval merged commit 81333cf into llvm:main Dec 18, 2024
9 of 10 checks passed
@clementval clementval deleted the cuf_host_array_constant branch December 18, 2024 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants